# coding:utf-8
# author:fxh

#字集-经典实现--2^n种集合
#python 特性
def subSet(nums):
    result = [[]]
    for num in nums:
        for element in result[:]:
            x = element[:]
            x.append(num)
            result.append(x)
    return result

# 回溯算法：重点理解（需要记忆下来）
def subsets_recursive(nums):
    lst = []
    result = []
    subsets_recursive_help(result,lst,nums,0)
    return result

def subsets_recursive_help(result,lst,nums,pos) :
    result.append(lst[:])
    for i in range(pos,len(nums)):
        lst.append(nums[i])
        subsets_recursive_help(result,lst,nums,i+1)
        lst.pop()




if __name__ == '__main__':
    print(subSet(['a','b','c']))

    print(subsets_recursive(['a','b']))
    #思考题：
    #1、为什么result[:]  2、x为什么用element[:]
    #
    # output : [[], ['a'], ['b'], ['a', 'b'], ['c'], ['a', 'c'], ['b', 'c'], ['a', 'b', 'c']]




